package com.slliver.pay.service.impl;

import com.slliver.commonmodel.pay.Pay;
import com.slliver.commonmodel.product.Product;
import com.slliver.pay.openfeign.MOJIWeatherFeignClient;
import com.slliver.pay.openfeign.ProductFeignClient;
import com.slliver.pay.service.PayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.time.LocalDateTime;
import java.util.Arrays;

@Slf4j
@Service
public class PayServiceImpl implements PayService {


    @Autowired
    private ProductFeignClient productFeignClient;

    @Override
    public Pay savePay(Long userId, Long productId) {
        Product product = productFeignClient.getProductById(productId, "accessToken="+LocalDateTime.now());
        Pay pay = new Pay();
        pay.setId(1001L);
        pay.setCreateDateTime(LocalDateTime.now());
        pay.setUserId(userId);
        pay.setProductList(Arrays.asList(product));
        return pay;
    }


    @Autowired
    private MOJIWeatherFeignClient weatherFeignClient ;
    @Override
    public String getWeather() {
        return weatherFeignClient.getWeather("APPCODE ece391895ca94491a59002294555a9c2",
                "50b53ff8dd7d9fa320d3d3ca32cf8ed1", "2182");
    }


}
